/**
 * 作者:TL(tongling19890103@126.com)
 * 时间：2020-07-17.
 * 功能：
 */

layui.use(['tree', 'layer','laypage','element','layedit'], function(){
    var layer = layui.layer
        ,laypage = layui.laypage
        ,element = layui.element
        ,layedit = layui.layedit
        ,$ = layui.jquery;
    /**
      * 知识管理详情页面
      */

    // 生成左侧菜单
    layui.tree({
        elem: '#treeMenu' //指定元素
        ,target: '_blank' //是否新选项卡打开（比如节点返回href才有效）
        ,click: function(item){ //点击节点回调
            layer.msg('当前节名称：'+ item.name + '<br>全部参数：'+ JSON.stringify(item));
            console.log(item);
        }
        ,nodes: [ //节点
            {
                name: '中电智恒'
                ,id: 1
                // ,alias: 'changyong'
                ,spread: true
                ,children: [
                    {
                        name: '知识库1'
                        ,id: 11
                        ,href: '#'
                        ,spread: true
                        ,children:[
                            {
                                name: '增值税'
                                ,id: 111
                                ,spread: true
                                ,children:[
                                    {
                                        name: '房地产'
                                        ,id: 1111
                                    }, {
                                        name: '发票'
                                        ,id: 1112
                                    }, {
                                        name: '金融'
                                        ,id: 1113
                                    }, {
                                        name: '文件库'
                                        ,id: 1113
                                    }
                                ]
                            }
                            ,{
                                name: '发票'
                                ,id: 112
                            }
                            ,{
                                name: '金融'
                                ,id: 113
                            }
                            ,{
                                name: '文件库'
                                ,id: 114
                                ,children:[
                                    {
                                        name: '文件库知1'
                                        ,id: 1141
                                    }, {
                                        name: '文件库知2'
                                        ,id: 1142
                                    }, {
                                        name: '文件库知3'
                                        ,id: 1143
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        name: '知识库2'
                        ,id: 12
                        ,href: '#'
                        ,children:[
                            {
                                name: '增值税'
                                ,id: 121
                                ,children:[
                                    {
                                        name: '房地产'
                                        ,id: 1211
                                    }, {
                                        name: '发票'
                                        ,id: 1212
                                    }, {
                                        name: '金融'
                                        ,id: 1213
                                    }, {
                                        name: '文件库'
                                        ,id: 1213
                                    }
                                ]
                            }, {
                                name: '发票'
                                ,id: 112
                            }, {
                                name: '金融'
                                ,id: 113
                            }, {
                                name: '文件库'
                                ,id: 114
                                ,children:[
                                    {
                                        name: '文件库知1'
                                        ,id: 1141
                                    }, {
                                        name: '文件库知2'
                                        ,id: 1142
                                    }, {
                                        name: '文件库知3'
                                        ,id: 1143
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        name: '知识库3'
                        ,id: 13
                        ,href: '#'
                        ,children:[
                            {
                                name: '增值税'
                                ,id: 131
                                ,children:[
                                    {
                                        name: '房地产'
                                        ,id: 1311
                                    }, {
                                        name: '发票'
                                        ,id: 1312
                                    }, {
                                        name: '金融'
                                        ,id: 1313
                                    }, {
                                        name: '文件库'
                                        ,id: 1313
                                    }
                                ]
                            }, {
                                name: '发票'
                                ,id: 132
                            }, {
                                name: '金融'
                                ,id: 133
                            }, {
                                name: '文件库'
                                ,id: 134
                                ,children:[
                                    {
                                        name: '文件库知1'
                                        ,id: 1341
                                    }, {
                                        name: '文件库知2'
                                        ,id: 1342
                                    }, {
                                        name: '文件库知3'
                                        ,id: 1343
                                    }
                                ]
                            }
                        ]
                    },
                ]
            }
        ]
    });

    // 历史版本弹层
    $("#historyPop,#knowleHistoty").on('click',function(){
        var histoyrData = [
            {id:'01',name:'张东阳',time:'2019.12.12',edition:'003'},
            {id:'02',name:'张东阳',time:'2020.01.12',edition:'002'},
            {id:'03',name:'张东阳',time:'2020.4.26',edition:'001'},
        ]
        var historyTemp = '';

        if(histoyrData.length<1){
            historyTemp = ' <tr>\n' +
                '  <td colspan="4" align="center">暂无内容</td>\n' +
                ' </tr>'
        }else{
            for(var i = 0;i<histoyrData.length;i++){
                historyTemp += '<tr>\n' +
                    '    <td align="center">'+histoyrData[i].edition+'</td>\n' +
                    '    <td align="center">'+histoyrData[i].name+'</td>\n' +
                    '    <td align="center">'+histoyrData[i].time+'</td>\n' +
                    '    <td align="center">' +
                    '       <a href="javascript:void(0)" class="historyeditbtn" data-id="'+histoyrData[i].id+'">' +
                    '           <i class="icon edit-btn"></i>' +
                    '       </a>' +
                    '    </td>\n' +
                    '</tr>'
            }
        }
        $("#history-table-items").html(historyTemp);
        $('#historyModal').modal('show');
        // $('#myModal').css('display','block');
    })
    // 历史版本弹层编辑按钮事件
    $(document).on('click','.historyeditbtn',function(){
        layer.msg('你选择的是'+$(this).data('id'))
    })
    // 切换li标签
    $(".bottomMain-info li").on('click',function(){
        var itemIndex = $(this).index()
        if($(this).hasClass('active')){
            return;
        }else{
            $(this).addClass('active').siblings().removeClass('active');
            $(this).parents(".tab-nav-box").find('.tab-nav-content').hide()
            $(this).parents(".tab-nav-box").find('.tab-nav-content').eq(itemIndex).show()
        }
    })
    $("#knowleLink").on("click",function(){
        layer.msg('你点击的是知识链接')
    })
    $("#knowlePush").on("click",function(){
        layer.msg('你点击的是推送')
    })
    $("#knowleStop").on("click",function(){
        layer.msg('你点击的是废止')
    })
    $("#knowleDownload").on("click",function(){
        layer.msg('你点击的是下载')
    })

    // 顶部信息折叠收起
    $(document).on("click",".info-folder-box",function(){
        var $elItem = $(this).find(".iconfont");
        if($elItem.hasClass("icon-shouqi")){
            $elItem.addClass("icon-zhankai").removeClass("icon-shouqi");
            $(".describe-content").hide();
        }else{
            $elItem.addClass("icon-shouqi").removeClass("icon-zhankai");
            $(".describe-content").show();
        }
    })

    /**
     * 知识管理页面
     */
    // 知识管理分页
    laypage.render({
        elem: 'knowManaPage'
        ,count: 100
        // ,first: false
        // ,last: false
        // ,prev: '<em><</em>'
        // ,next: '<em>></em>'
        ,jump: function(obj){
            console.log(obj)
            // 当前页点击
            var currentPage = obj.curr;
            var resultData = [
                {
                    id:0
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:1
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:2
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:3
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:4
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:5
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:6
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:7
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:8
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
                ,{
                    id:9
                    ,name:'房地产知识标题'
                    ,show:true
                    ,time:'2019.11.24 13:00'
                    ,creater:'张东阳'
                    ,createrNo:'D483924'
                }
            ]
            var resultItemsTemp = ''
            for(var i = 0;i<resultData.length;i++){
                resultItemsTemp += '<tr data-id="'+resultData[i].id+'">\n' +
                        '  <td>'+resultData[i].name+'</td>\n' +
                        '  <td>'+(resultData[i].show?"是":"否")+'</td>\n' +
                        '  <td>'+resultData[i].time+'</td>\n' +
                        '  <td>'+resultData[i].creater+'</td>\n' +
                        '  <td>'+resultData[i].createrNo+'</td>\n' +
                        '  <td>\n' +
                        '     <a href="javascript:void(0)" class="detail-btn"><img src="../../image/detail.png" alt=""></a>'+
                        '     <a href="javascript:void(0)" class="edit-btn"><img src="../../image/edit.png" alt=""></a>'+
                        '     <a href="javascript:void(0)" class="publish-btn"><img src="../../image/publish.png" alt=""></a>'+
                        '     <a href="javascript:void(0)" class="delete-btn"><img src="../../image/abolish1.png" alt=""></a>'+
                        '  </td>\n' +
                    '  </tr>'
            }
            $("#konwManaList").html(resultItemsTemp)
        }
    });
    // 知识管理-批量导入按钮
    $(document).on('click','.knowMana-import',function(){
        layer.msg('你点击的是"批量导入"')
    })
    // 知识管理编辑按钮点击事件
    $(document).on('click','#konwManaList .edit-btn',function(){
       var listId = $(this).parents('tr').data('id');
       layer.msg('你选择的是'+listId);
       setTimeout(function(){ window.location.href="knowMana-detail.html" }, 3000)

    })
    // 知识管理删除按钮点击事件
    $(document).on('click','#konwManaList .delete-btn',function(){
       var listId = $(this).parents('tr').data('id');
       layer.msg('你删除的是'+listId)
    })


});

